<template>
  <view class="new_comer_challenge">
    <view class="head">
      <view class="left" @click="back"
        ><uni-icons color="black" size="24" type="left"
      /></view>
      <view class="title">{{ title }}</view>
      <view></view>
    </view>

    <scroll-view scroll-y class="scroll_view">
      <view class="scroll_main">
        <view
          class="giftItem"
          v-for="(item, index) in list"
          :key="index"
          @click="getGift(item)"
        >
          <view class="image-container">
            <image
              v-if="item.status === 'wait'"
              class="item-img"
              src="/static/icon/icon_task_type1.png"
              mode="widthFix"
            />
            <image
              v-else-if="item.status === 'done'"
              class="item-img"
              src="/static/icon/icon_task_type2.png"
            />
            <image
              v-else-if="item.status == 'gift1'"
              src="/static/icon/icon_task_type3.png"
              class="item-img gift-img"
            />
            <image
              v-else-if="item.status == 'gift2'"
              src="/static/icon/icon_task_type4.png"
              class="item-img gift-img"
            />
            <image
              v-else-if="item.status == 'gift3'"
              src="/static/icon/icon_task_type5.png"
              class="item-img gift-img"
            />
          </view>

          <text class="day" :class="[item.status]">{{ item.title }}</text>
        </view>
      </view>
    </scroll-view>

    <VigorGetterAlert v-model="showVigor" />
  </view>
</template>
<script>
import VigorGetterAlert from "./components/drawer/VigorGetterAlert.vue";

const statusList = ["wait", "done", "gift1", "gift2", "gift3"]; // 5种状态
const weights = [50, 35, 5, 5, 5];

const testList = Array.from({ length: 31 }, (_, i) => {
  // 根据权重随机选择状态
  const random = Math.random() * 100;
  let cumulativeWeight = 0;
  let selectedStatus = "wait";

  for (let j = 0; j < statusList.length; j++) {
    cumulativeWeight += weights[j];
    if (random <= cumulativeWeight) {
      selectedStatus = statusList[j];
      break;
    }
  }

  return {
    id: i + 1, // 从1开始
    title: `${i + 1}`,
    status: selectedStatus,
  };
});

export default {
  components: {
    VigorGetterAlert,
  },
  data() {
    return {
      showVigor: false,
      list: testList,
    };
  },

  computed: {
    progress() {
      return (
        (this.list.filter((item) => item.status !== "will").length - 1) * 15
      );
    },

    title() {
      if (this.list.length === 0 || this.list.length === 7) {
        return "新人七日挑战";
      }
      return "三十日挑战";
    },
  },

  methods: {
    back() {
      uni.navigateBack();
    },

    getGift(gift) {
      if (gift.status === "gift1" || gift.status === "gift2" || gift.status === "gift3") {
        this.showVigor = true;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.new_comer_challenge {
  width: 100vw;
  height: 100vh;
  padding: var(--status-bar-height) 30rpx;
  background-image: url("@/static/ring/ill/ill_bg.png");
  background-size: 100% 100%;
  background-repeat: repeat;
  background-position: center;

  .head {
    width: 100%;
    padding: 0 10rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8rpx;

    view {
      flex: 1;
    }

    .title {
      font-weight: 500;
      font-size: 36rpx;
      color: black;
      text-align: center;
    }

    .left {
      text-align: left;
    }
  }

  .scroll_view {
    width: 100%;
    height: calc(100vh - var(--status-bar-height) - 88rpx);

    .scroll_main {
      width: 100%;
      display: grid;
      grid-template-columns: repeat(6, 1fr);
      gap: 8px;
      row-gap: 15px;
      padding-top: 60rpx;

      .giftItem {
        width: 100%;
        height: 136rpx;
        background-color: rgba($color: #ffffff, $alpha: 0.4);
        border-radius: 16rpx;

        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        .day {
          font-weight: bold;
          font-size: 28rpx;
          color: #999999;

          &.ing {
            color: #2359f8;
          }

          &.will {
            color: black;
          }
        }
      }
    }
  }
}

.image-container {
  width: 32px;
  height: 32px;
  position: relative;
}
.item-img {
  width: 24px;
  height: 24px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.gift-img {
  width: 56px;
  height: 56px;
	top: 55%;
}
</style>
